{extend name="layouts/cms"}
{block name='body-content'}

<button class="layui-btn layui-btn-normal"
        onclick="addConfig()">
    <i class="layui-icon">&#xe608;</i> 添加配置
</button>

<div class="layui-inline layui-form">
    <form class="form-search" action="{:url('cms/config/index')}" method="get">
        <div class="layui-input-inline">
            <input type="hidden" name="record_num" class="record_num" value="<?php echo $record_num; ?>">
            <input type="hidden" name="page_limit" class="page_limit" value="{$page_limit}">
            <input type="hidden" name="curr_page" class="curr_page" value="1">
            <input type="text" value="{$search}" name="str_search" placeholder="请输入标题/标签"
                   class="layui-input search_input">
        </div>
        <button class="layui-btn-warm btn-search-mz">
            <i class="layui-icon">&#xe615;</i>
        </button>

        <div class="layui-input-inline">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <input type="radio" name="type" value="text" title="文本" {$type=="text"?"checked":""}>
                <span class="layui-badge layui-bg-orange">{$arrCount['WB']}</span>
                <input type="radio" name="type" value="checkbox" title="开关" {$type=="checkbox"?"checked":""}>
                <span class="layui-badge layui-bg-orange">{$arrCount['KG']}</span>
                <input type="radio" name="type" value="button" title="图片" {$type=="button"?"checked":""}>
                <span class="layui-badge layui-bg-orange">{$arrCount['TP']}</span>
            </div>
        </div>
    </form>

</div>

<table class="layui-table table-body" lay-even="" lay-skin="row">
    <colgroup>
        <col width="5%">
        <col width="15%">
        <col width="15%">
        <col width="20%">
        <col width="20%">
        <col width="10%">
        <col width="5%">
        <col width="10%">
    </colgroup>
    <thead>
    <tr>
        <th>ID</th>
        <th>标题</th>
        <th>标签</th>
        <th>取值</th>
        <th>提示</th>
        <th>添加时间</th>
        <th>排序</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody class="tbody-configs layui-form">
    {volist name="configs" id="vo"}
    <tr class="tr-config-{$vo['id']}">
        <td>{$vo['id']}</td>
        <td>{$vo.title}</td>
        <td>{$vo['tag']}</td>
        <td>
            {php}echo htmlspecialchars_decode($vo['value_tip']);{/php}
        </td>
        <td class="td-00EE00">
            <span class="span-FF9233">{$vo['tip']}</span>
        </td>
        <td>{$vo.add_time}</td>
        <td>{$vo['list_order']}</td>
        <td>
            <div class="layui-btn-group">
                <button class="layui-btn layui-btn-sm"
                        onclick="editConfig('{$vo.id}')">
                    <i class="layui-icon">&#xe642;</i>
                </button>
                <button class="layui-btn layui-btn-sm"
                        onclick="delConfig('{$vo.id}')">
                    <i class="layui-icon">&#xe640;</i>
                </button>
            </div>
        </td>
    </tr>
    {/volist}
    </tbody>
</table>

<div id="demo2-1"></div>
<link href="__CMS__/css/orders.css" rel="stylesheet">
{/block}

{block name='single-content'}
<script src="__CMS__/js/configs.js"></script>
<script src="__CMS__/js/moZhang.js"></script>
<script>
    //添加配置项
    function addConfig() {
        var toUrl = "{:url('cms/config/add')}";
        ToOpenPopups(toUrl, '✚ 添加配置', '', '76%');
    }

    layui.use(['laypage', 'layer'], function () {
        var laypage = layui.laypage;
        var page_limit = $(".page_limit").val();
        var record_num = $(".record_num").val();
        laypage.render({
            elem: 'demo2-1'
            , limit: page_limit
            , count: record_num
            , layout: ['count', 'prev', 'page', 'next', 'refresh', 'skip']
            , jump: function (obj, first) {
                //obj包含了当前分页的所有参数
                //首次不执行
                if (!first) {
                    //layer.msg(obj.curr);
                    ajaxOpForPageConfig(obj.curr);
                }
            }
            , theme: '#FF5722'
        });
    });
</script>
<script>

    function delConfig(id) {
        var toUrl = "{:url('cms/config/edit',['id'=>'AID'])}";
        toUrl = toUrl.replace('AID', id);
        ToDelItem(id, toUrl, '.tr-order-' + id);
    }
    function editConfig(id) {
        var toUrl = "{:url('cms/config/edit',['id'=>'AID'])}";
        toUrl = toUrl.replace('AID', id);
        ToOpenPopups(toUrl, '✎ 配置修改', '', '76%');
    }

    $(".btn-search-mz").on('click', function () {
        $(".form-search").submit();
    });

    //通过ajax 获取分页数据
    function ajaxOpForPageConfig(curr_page) {
        var toUrl = "{:url('cms/config/ajaxOpForConfigsPage')}";
        $(".curr_page").val(curr_page);
        var postData = $(".form-search").serialize();
        ToAjaxOpForPageConfigs(toUrl, postData);
    }
</script>
{/block}